//
//  CTMLCHeaderView.m
//  09-静态单元格
//
//  Created by Sizhu Ba on 2017/9/11.
//  Copyright © 2017年 mac. All rights reserved.
//


#import "CTMLCHeaderView.h"
#import "QTapGesture.h"
#import "CTMLObj.h"
@interface CTMLCHeaderView ()
@property (nonatomic, strong) UIView * bgv;
@property (nonatomic, strong) UILabel * descLbl;
@property (nonatomic, strong) UIButton * imgBtn;


@end
@implementation CTMLCHeaderView



-(instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self!=nil) {
       self.bgv = [[UIView alloc]initWithFrame:CGRectMake(15, 0, UIScreen.mainScreen.bounds.size.width-30, 50)];
        self.bgv.backgroundColor = [UIColor orangeColor];// [self RGBAsame:233.0 andA:1.0];
        self.bgv.layer.borderColor = [[self RGBAsame:211.0 andA:1.0] CGColor];//边框颜色
        self.bgv.layer.borderWidth = 1.0;//设置边框
        self.bgv.layer.cornerRadius = 5;
        self.bgv.layer.masksToBounds = true;
        
        CGFloat imgw = 30.0;
        self.imgBtn = [[UIButton alloc]initWithFrame:CGRectMake(self.bgv.frame.size.width-imgw, (self.bgv.frame.size.height-imgw)/2.0, imgw, imgw)];
        self.imgBtn.userInteractionEnabled = false;
        [self.imgBtn setImage:[UIImage imageNamed:@"jiahao"] forState:UIControlStateNormal];
        [self.imgBtn setImage:[UIImage imageNamed:@"jianhao"] forState:UIControlStateSelected];
        self.imgBtn.imageView.contentMode = UIViewContentModeScaleAspectFit;
        self.imgBtn.contentEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 10);
        [self.bgv addSubview:self.imgBtn];
        
        self.descLbl = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, self.bgv.frame.size.width-imgw-10, self.bgv.frame.size.height )];
        self.descLbl.font = [UIFont systemFontOfSize:13.0];
        self.descLbl.textColor = [UIColor blackColor];
        self.descLbl.text = @"测试用的";
        //self.textAlignment = NSTextAlignmentLeft;
        self.descLbl.backgroundColor = self.bgv.backgroundColor;
        
        [self.bgv addSubview:self.descLbl];
        
        [self addSubview:self.bgv];
        [QTapGesture addguest:self.bgv andAction:^(id obj) {
           
            if (self.tap !=nil) {
                self.tap(obj);
            }
        }];
    }
    return self;
}
-(void)setInfo:(CTMLObj *)obj {
    
    self.descLbl.text = obj.name;
    [self.imgBtn setSelected:obj.isopen];
   
}


/**
 * 设置颜色
 */
-(UIColor *)RGBAsame:(CGFloat) RGB andA:(CGFloat) A {
    
    return [UIColor colorWithRed:RGB/255.0 green:RGB/255.0 blue:RGB/255.0 alpha:A];
    
}
@end
